﻿namespace System.Net.Util
{
    internal class DoubleLink
    {
        internal DoubleLink _next;
        internal DoubleLink _prev;
        internal object Item;
        
        internal DoubleLink() { _next = _prev = this; }
        internal DoubleLink(object item) : this() { Item = item; }

        internal void InsertAfter(DoubleLink after)
        {
            _prev = after;
            _next = after._next;
            after._next = this;
            _next._prev = this;
        }

        internal void InsertBefore(DoubleLink before)
        {
            _prev = before._prev;
            _next = before;
            before._prev = this;
            _prev._next = this;
        }

        internal void Remove()
        {
            _prev._next = _next;
            _next._prev = _prev;
            _next = _prev = this;
        }

        internal DoubleLink Next
        {
            get { return _next; }
        }
    }
}
